<?php namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;

class MemberController extends Controller {
    public function getIndex(Request $request)
    {
        $name = trim($request->get('name', ''));
        $appends = [];

        $query = User::where('type','!=','0')
            ->orderBy('id', 'asc');
        if($name){
            $query = $query->where('name','like',"%".$name."%");
        }
        $list = $query->paginate(\Config::get('site.admin.pageSize'));
        $typeList = [
            '1' => '注册会员',
            '2' => '普通会员',
            '3' => '银牌会员',
            '4' => '金牌会员',
            '5' => '钻石会员',
            '9' => '过期会员'
        ];
        return view('admin.member.index')->with([
            'list' => $list,
            'name' => $name,
            'typeList'  => $typeList,
            'appends' => $appends]);
    }

    public function getUpdate($id = 0)
    {
        $model = User::findOrNew($id);
        return view('admin.member.update')->with(['model' => $model]);
    }

    public  function postUpdate(Request $request, $id =0){
        $data = $request->all();
        $model = User::findOrNew($id);
        $model->type    = $data['type'];
        $model->deadline= $data['deadline'];
        $model->save();
        $ret = ['state' => 'success', 'message' => '修改成功'];
        return \Response::json($ret);
    }
}